<template>
  <page-layout :avatar="currUser.name" style="margin-top: 5px">
    <div slot="headerContent">
      <div class="title">{{ msg }}，{{ currUser.name }}</div>
      <div>搬砖工程师 | 粤为科技 - 前端搬砖部</div>
    </div>
    <template>
      <a-row style="margin: 0 40px 0 10px">
        <a-col
          class="left-wrapper"
          :xl="24"
          :lg="24"
          :md="24"
          :sm="24"
          :xs="24"
        >
          <!-- 需求数据框 -->
          <a-card
            :class="{ 'project-list': true, anim: animate == true }"
            style="margin-bottom: 24px"
            :bordered="false"
            title="需求情况"
            :body-style="{ padding: 0 }"
          >
            <a
              :href="`#/demand/processing`"
              slot="extra"
              v-if="userInfo.permissions.requirements"
              >需求列表</a
            >
            <div style="background-color: #fff; padding: 20px">
              <a-row :gutter="16">
                <a-col :span="8">
                  <a-card
                    title="本月新增"
                    :bordered="false"
                    size="small"
                    :hoverable="true"
                    class="card-grid"
                  >
                    <p
                      style="
                        fontsize: 40px;
                        color: rgba(0, 0, 0, 0.85);
                        marginbottom: 16px;
                        fontweight: 500;
                      "
                    >
                      {{ requirementNum.new_count }}
                    </p>
                  </a-card>
                </a-col>
                <a-col :span="8">
                  <a-card
                    title="正在进行"
                    :bordered="false"
                    size="small"
                    :hoverable="true"
                  >
                    <!-- <p v-if="requirementNum.new_count">{{requirementNum.new_count}}</p> -->
                    <p
                      style="
                        fontsize: 40px;
                        color: rgba(0, 0, 0, 0.85);
                        marginbottom: 16px;
                        fontweight: 500;
                      "
                    >
                      {{ requirementNum.doing_count }}
                    </p>
                  </a-card>
                </a-col>
                <a-col :span="8">
                  <a-card
                    title="总数"
                    :bordered="false"
                    size="small"
                    :hoverable="true"
                  >
                    <p
                      style="
                        fontsize: 40px;
                        color: rgba(0, 0, 0, 0.85);
                        marginbottom: 16px;
                        fontweight: 500;
                      "
                    >
                      {{ requirementNum.total_count }}
                    </p>
                  </a-card>
                </a-col>
              </a-row>
              <br />
              <a-button
                type="link"
                style="margin-right: 10px"
                :href="`#/demand/add?random=${random}`"
                v-if="userInfo.permissions.requirements_insert"
              >
                创建
              </a-button>
              <a-button
                type="link"
                style="margin-right: 10px; opacity: 0"
                v-else
              >
                创建
              </a-button>
              <a-button
                type="primary"
                style="margin-left: 210px; opacity: 0"
                :href="`#/demand/processing`"
              >
                列表<a-icon type="right" />
              </a-button>
            </div>
          </a-card>
          <!-- 任务数据框 -->
          <a-card
            :class="{ 'project-list': true, anim: animate == true }"
            style="margin-bottom: 24px"
            :bordered="false"
            title="任务情况"
            :body-style="{ padding: 0 }"
          >
            <a
              :href="`#/task/processing`"
              slot="extra"
              v-if="userInfo.permissions.task"
              >任务列表</a
            >
            <div style="background-color: #fff; padding: 20px">
              <a-row :gutter="16">
                <a-col :span="8">
                  <a-card
                    title="本月新增"
                    :bordered="false"
                    size="small"
                    :hoverable="true"
                  >
                    <p
                      style="
                        fontsize: 40px;
                        color: rgba(0, 0, 0, 0.85);
                        marginbottom: 16px;
                        fontweight: 500;
                      "
                    >
                      {{ taskNum.new_count }}
                    </p>
                  </a-card>
                </a-col>
                <a-col :span="8">
                  <a-card
                    title="正在进行"
                    :bordered="false"
                    size="small"
                    :hoverable="true"
                  >
                    <!-- <p v-if="requirementNum.new_count">{{requirementNum.new_count}}</p> -->
                    <p
                      style="
                        fontsize: 40px;
                        color: rgba(0, 0, 0, 0.85);
                        marginbottom: 16px;
                        fontweight: 500;
                      "
                    >
                      {{ taskNum.doing_count }}
                    </p>
                  </a-card>
                </a-col>
                <a-col :span="8">
                  <a-card
                    title="总数"
                    :bordered="false"
                    size="small"
                    :hoverable="true"
                  >
                    <p
                      style="
                        fontsize: 40px;
                        color: rgba(0, 0, 0, 0.85);
                        marginbottom: 16px;
                        fontweight: 500;
                      "
                    >
                      {{ taskNum.total_count }}
                    </p>
                  </a-card>
                </a-col>
              </a-row>
              <br />
              <a-button
                type="link"
                style="margin-right: 10px"
                :href="`#/task/add?random=${random}`"
                v-if="userInfo.permissions.task_insert"
              >
                创建
              </a-button>
              <a-button
                type="link"
                style="margin-right: 10px; opacity: 0"
                v-else
              >
                创建
              </a-button>
              <a-button
                type="primary"
                style="margin-left: 210px; opacity: 0"
                :href="`#/task/processing`"
              >
                列表<a-icon type="right" />
              </a-button>
            </div>
          </a-card>
          <!-- 项目数据框 -->
          <a-card
            :class="{ 'project-list': true, anim: animate == true }"
            style="margin-bottom: 24px"
            :bordered="false"
            title="项目情况"
            :body-style="{ padding: 0 }"
          >
            <a
              :href="`#/project/index`"
              slot="extra"
              v-if="userInfo.permissions.projects"
              >项目列表</a
            >
            <div style="background-color: #fff; padding: 20px">
              <a-row :gutter="16">
                <a-col :span="8">
                  <a-card
                    title="本月新增"
                    :bordered="false"
                    size="small"
                    :hoverable="true"
                  >
                    <p
                      style="
                        fontsize: 40px;
                        color: rgba(0, 0, 0, 0.85);
                        marginbottom: 16px;
                        fontweight: 500;
                      "
                    >
                      {{ projectNum.new_count }}
                    </p>
                  </a-card>
                </a-col>
                <a-col :span="8">
                  <a-card
                    title="正在进行"
                    :bordered="false"
                    size="small"
                    :hoverable="true"
                  >
                    <!-- <p v-if="requirementNum.new_count">{{requirementNum.new_count}}</p> -->
                    <p
                      style="
                        fontsize: 40px;
                        color: rgba(0, 0, 0, 0.85);
                        marginbottom: 16px;
                        fontweight: 500;
                      "
                    >
                      {{ projectNum.doing_count }}
                    </p>
                  </a-card>
                </a-col>
                <a-col :span="8">
                  <a-card
                    title="总数"
                    :bordered="false"
                    size="small"
                    :hoverable="true"
                  >
                    <p
                      style="
                        fontsize: 40px;
                        color: rgba(0, 0, 0, 0.85);
                        marginbottom: 16px;
                        fontweight: 500;
                      "
                    >
                      {{ projectNum.total_count }}
                    </p>
                  </a-card>
                </a-col>
              </a-row>
              <br />

              <a-button
                type="link"
                style="margin-right: 10px"
                :href="`#/project/add?${random}`"
                v-if="userInfo.permissions.projects_insert"
              >
                创建
              </a-button>
              <a-button
                type="link"
                style="margin-right: 10px; opacity: 0"
                v-else
              >
                创建
              </a-button>
              <a-button
                type="primary"
                style="margin-left: 210px; opacity: 0"
                :href="`#/task/processing`"
              >
                列表<a-icon type="right" />
              </a-button>
            </div>
          </a-card>
          <!-- 产品数据框 -->
          <a-card
            :class="{ 'project-list': true, anim: animate == true }"
            style="margin-bottom: 24px"
            :bordered="false"
            title="产品情况"
            :body-style="{ padding: 0 }"
          >
            <a
              :href="`#/produce/index`"
              slot="extra"
              v-if="userInfo.permissions.produces_index"
              >产品列表</a
            >
            <div style="background-color: #fff; padding: 20px">
              <a-row :gutter="16">
                <a-col :span="8">
                  <a-card
                    title="本月新增"
                    :bordered="false"
                    size="small"
                    :hoverable="true"
                    style="width: "
                  >
                    <p
                      style="
                        fontsize: 40px;
                        color: rgba(0, 0, 0, 0.85);
                        marginbottom: 16px;
                        fontweight: 500;
                      "
                    >
                      {{ produceNum.new_count }}
                    </p>
                  </a-card>
                </a-col>
                <a-col :span="8">
                  <a-card
                    title="正在进行"
                    :bordered="false"
                    size="small"
                    :hoverable="true"
                  >
                    <!-- <p v-if="requirementNum.new_count">{{requirementNum.new_count}}</p> -->
                    <p
                      style="
                        fontsize: 40px;
                        color: rgba(0, 0, 0, 0.85);
                        marginbottom: 16px;
                        fontweight: 500;
                      "
                    >
                      0
                    </p>
                  </a-card>
                </a-col>
                <a-col :span="8">
                  <a-card
                    title="总数"
                    :bordered="false"
                    size="small"
                    :hoverable="true"
                  >
                    <p
                      style="
                        fontsize: 40px;
                        color: rgba(0, 0, 0, 0.85);
                        marginbottom: 16px;
                        fontweight: 500;
                      "
                    >
                      {{ produceNum.total_count }}
                    </p>
                  </a-card>
                </a-col>
              </a-row>
              <br />
              <a-button
                type="link"
                style="margin-right: 10px"
                :href="`#/project/add?${random}`"
                v-if="userInfo.permissions.produce_insert"
              >
                创建
              </a-button>
              <a-button
                type="link"
                style="margin-right: 10px; opacity: 0"
                :href="`#/project/add?${random}`"
                v-else
              >
                创建
              </a-button>
              <a-button
                type="primary"
                style="margin-left: 210px; opacity: 0"
                :href="`#/produce/index`"
              >
                列表<a-icon type="right" />
              </a-button>
            </div>
          </a-card>
        </a-col>

        <a-col style="" :xl="24" :lg="24" :md="24" :sm="24" :xs="24">
          <!-- 进行中的项目 -->
          <!-- <a-card
            :class="{ 'project-list': true, anim: animate == true }"
            style="margin-bottom: 24px"
            :bordered="false"
            title="进行中的项目"
            :body-style="{ padding: 0 }"
          >
            <a :href="`#/project/index?random=${random}`" slot="extra" v-if='userInfo.permissions.projects'
              >全部项目</a
            >
            <div>
              <a-card-grid
                @click="
                  () =>project_jump(item.id)
                "
                :key="item.id"
                v-for="item in project"
              >
                <a-card
                  :bordered="false"
                  :body-style="{ padding: 0, height: '135px' }"
                  class="card-grid"
                >
                  <a-card-meta :description="item.desc">
                    <div slot="title" class="card-title">
                      <span>{{ item.title }}</span>
                    </div>
                  </a-card-meta>
                  <div class="project-item">
                    <span class="group">{{ item.department_name }}</span>
                    <span class="datetime">{{ item.status_name }}</span>
                  </div>
                </a-card>
              </a-card-grid>
           
            </div>
          </a-card> -->

          <a-card
            :class="{ 'project-list': true, anim: animate == true }"
            style="margin-bottom: 24px"
            :bordered="false"
            title="进行中"
            :body-style="{ padding: 0 }"
          >
            <a-tabs default-active-key="1">
              <a-tab-pane key="1" tab="任务">
                <a-table
                  :columns="task_columns"
                  :data-source="doingTask"
                  @change="onChange"
                  :loading="loading"
                  :pagination="task_pagination"
                  :scroll="{ y: 480 }"
                >
                  <div slot="truly_time" slot-scope="text, record">
                    <template v-if="text != null">
                      <a
                        style="text-decoration: underline"
                        @click="log_info(record.key)"
                        title="点击查看任务日志"
                      >
                        {{ text }}
                      </a>
                    </template>
                    <template v-else>
                      <a style="text-decoration: underline"> 暂未开始 </a>
                    </template>
                  </div>
                  <div slot="status" slot-scope="text">
                    <template v-if="text == 1">
                      <a-tag
                        style="
                          width: 70px;
                          height: 30px;
                          text-align: center;
                          line-height: 30px;
                        "
                        color="#2591FF"
                      >
                        待开始
                      </a-tag>
                    </template>
                    <template v-else-if="text == 2">
                      <a-tag
                        style="
                          width: 70px;
                          height: 30px;
                          text-align: center;
                          line-height: 30px;
                        "
                        color="#FF6D25"
                      >
                        进行中
                      </a-tag>
                    </template>
                    <template v-else-if="text == 3">
                      <a-tag
                        style="
                          width: 70px;
                          height: 30px;
                          text-align: center;
                          line-height: 30px;
                        "
                        color="#f5222d"
                      >
                        超时
                      </a-tag>
                    </template>
                    <template v-else>
                      <a-tag
                        style="
                          width: 70px;
                          height: 30px;
                          text-align: center;
                          line-height: 30px;
                        "
                        color="#4E25FF"
                      >
                        测试验收
                      </a-tag>
                    </template>
                  </div>
                  <!-- eslint-disable-next-line -->
                  <div slot="action" slot-scope="{ text, record }">
                    <!-- {{ record.key }} -->

                    <a
                      v-if="userInfo.permissions.task_detail"
                      :href="`#/task/detail?random=${random}&&id=${record.key}`"
                      style="margin-right: 8px"
                      >查看</a
                    >
                    <a
                      v-if="userInfo.permissions.task_edit"
                      :href="`#/task/add?random=${random}&&id=${record.key}`"
                      style="margin-right: 8px"
                      >| 编辑</a
                    >
                    <a-popconfirm
                      v-if="
                        record.status < 2 && userInfo.permissions.task_delete
                      "
                      title="确定删除该任务吗?"
                      ok-text="是的"
                      cancel-text="取消"
                      @confirm="() => confirm(record.key)"
                    >
                      <a>| 删除</a>
                    </a-popconfirm>
                    <template
                      v-if="
                        text.engineer_id === userId &&
                        userInfo.permissions.task_start
                      "
                    >
                      <a href="">| </a>
                      <a-popconfirm
                        title="确定开始此任务吗?"
                        ok-text="是的"
                        cancel-text="取消"
                        v-if="!record.log_status || record.log_status == 3"
                        @confirm="() => start_task(record.key)"
                      >
                        <a>
                          <!-- {{ record.log_status }} -->
                          <a-icon
                            style="margin-right: 5px"
                            type="play-circle"
                            title="开始"
                          ></a-icon
                        ></a>
                      </a-popconfirm>
                      <a>
                        <a-icon
                          v-if="record.log_status == 1"
                          @click="showPauseModal(record.key)"
                          type="pause-circle"
                          title="暂停"
                          style="margin-right: 5px"
                        ></a-icon>
                      </a>
                      <a-modal
                        title="任务暂停备注"
                        destroyOnClose
                        :visible="pause_visible"
                        :confirm-loading="pause_confirmLoading"
                        @ok="() => pause_handleOk(record.key)"
                        @cancel="pause_handleCancel"
                      >
                        <a-form
                          id="components-form-demo-normal-login"
                          ref="pause_form"
                          :form="pause_form"
                          class="login-form"
                          v-bind="{
                            labelCol: { span: 6 },
                            wrapperCol: { span: 14 }
                          }"
                        >
                          <a-form-item label="任务暂停备注">
                            <a-textarea
                              v-decorator="[
                                'desc',
                                {
                                  rules: [
                                    {
                                      required: true,
                                      message: '此处填写任务暂停备注!'
                                    }
                                  ]
                                }
                              ]"
                              placeholder="此处填写任务暂停备注"
                            >
                            </a-textarea>
                          </a-form-item>
                        </a-form>
                      </a-modal>
                      <a>
                        <a-icon
                          @click="showSuspendModal(record.key)"
                          type="stop"
                          title="中止"
                          style="margin-right: 5px; color: #f5222d"
                        ></a-icon>
                      </a>
                      <a-modal
                        title="中止任务"
                        :visible="suspend_visible"
                        :confirm-loading="suspend_confirmLoading"
                        @ok="suspend_handleOk(record.key)"
                        @cancel="suspend_handleCancel"
                      >
                        <a-form
                          id="components-form-demo-normal-login"
                          ref="suspend_form"
                          :form="suspend_form"
                          class="login-form"
                          v-bind="{
                            labelCol: { span: 6 },
                            wrapperCol: { span: 14 }
                          }"
                        >
                          <a-form-item label="中止原因">
                            <a-textarea
                              v-decorator="[
                                'desc',
                                {
                                  rules: [
                                    {
                                      required: true,
                                      message: '请备注任务中止原因!'
                                    }
                                  ]
                                }
                              ]"
                              placeholder="任务中止原因"
                            >
                            </a-textarea>
                          </a-form-item>
                        </a-form>
                      </a-modal>
                      <a-popconfirm
                        title="确定完成此任务吗?"
                        ok-text="是的"
                        cancel-text="取消"
                        @confirm="() => finish_task(record.key, '完成任务')"
                      >
                        <a>
                          <a-icon
                            type="check-circle"
                            title="完成"
                            style="margin-right: 5px"
                          />
                        </a>
                      </a-popconfirm>
                    </template>
                  </div>
                  <template slot="statusTitle">
                    <a-icon
                      @click.native="onStatusTitleClick"
                      type="info-circle"
                    />
                  </template>
                </a-table>
              </a-tab-pane>
              <a-tab-pane key="2" tab="需求" force-render>
                <a-table
                  :columns="requirement_columns"
                  :data-source="doingRequirement"
                  :pagination="{ pageSize: 50 }"
                  :scroll="{ y: 480 }"
                >
                  <template slot="requirement_title" slot-scope="text, record">
                    <a
                      :href="`#/demand/detail?random=${random}&&id=${record.requirement_id}`"
                      >{{ text }}
                    </a>
                  </template>
                  <template slot="task_count" slot-scope="task_count, record">
                    <a
                      @click="task_infos(record.requirement_id)"
                      title="查看该需求下的任务的执行情况"
                    >
                      {{ task_count }}
                    </a>
                  </template>
                  <template slot="requirement_status" slot-scope="text">
                    <a-tag
                      :style="`
                  width: 70px;
                  height: 30px;
                  text-align: center;
                  line-height: 30px;
                `"
                      :color="RequirementStatus[text ? text - 1 : 0].color"
                    >
                      {{ RequirementStatus[text ? text - 1 : 0].text }}
                    </a-tag>
                  </template>
                </a-table>
              </a-tab-pane>
              <a-tab-pane key="3" tab="项目">
                Content of Tab Pane 3
              </a-tab-pane>
              <a-tab-pane key="4" tab="产品">
                Content of Tab Pane 4
              </a-tab-pane>
            </a-tabs>
            <!-- <a
              :href="`#/demand/processing?random=${random}`"
              slot="extra"
              v-if="userInfo.permissions.requirements"
              >更多</a
            > -->
          </a-card>

          <!-- 动态 -->
          <!-- <a-card title="动态" :bordered="false" class="activities">
            <a-spin :spinning="loading" class="spinning">
              <a-list style="height: 240px; overflow: auto">
                <a-list-item :key="index" v-for="(item, index) in activities">
                  <a-list-item-meta>
                    <a-avatar
                      slot="avatar"
                      :style="{
                        backgroundColor: avatarColor[item.user_name.length],
                        verticalAlign: 'middle'
                      }"
                    >
                      {{ item.user_name.slice(0, 1) }}</a-avatar
                    >
                    <div class="title" slot="title">{{ item.user_name }}</div>
                    <div class="content" slot="description">
                      {{ item.remark }}
                    </div>
                  </a-list-item-meta>
                  <div class="time">{{ item.updated_at }}</div>
                </a-list-item>
              </a-list>
            </a-spin>
            <a-pagination
              style="margin-top: 15px"
              v-model="current"
              :total="total"
              :defaultPageSize="15"
              @change="paginationChange"
            />
          </a-card> -->
        </a-col>
      </a-row>
    </template>
    <a-modal
      :footer="null"
      :destroyOnClose="true"
      v-model="task_visible"
      title="变更记录"
      ok-text="确认"
      @ok="hideModal"
      @cancel="hideModal"
      width="580px"
    >
      <a-table bordered :data-source="task_data" :columns="task_columns1">
        <template slot="haha" slot-scope="text, record">
          <a
            :href="`#/task/detail?random=${random}&&id=${record.task_id}`"
            @click="hideModal"
          >
            {{ text }}</a
          >
        </template>
      </a-table>
    </a-modal>
  </page-layout>
</template>
<script>
/* eslint-disable no-unused-vars */
import PageLayout from "@/layouts/PageLayout";
import { tasks as demand_task } from "@/services/demand";
import { mapState } from "vuex";
import {
  doing_requirements,
  doing_task,
  projects,
  requirements,
  tasks,
  logs,
  produces,
  ongoing_projects
} from "@/services/workPlace";

// import { request, METHOD } from "@/utils/request";
const requirement_columns = [
  {
    title: "需求名称",
    dataIndex: "title",
    // sorter: true,
    width: "15%",
    key: "title",
    scopedSlots: { customRender: "requirement_title" }
  },
  {
    title: "当前状态",
    dataIndex: "status",
    scopedSlots: { customRender: "requirement_status" },
    key: "status"
  },
  {
    title: "提交时间",
    dataIndex: "created_at",
    key: "created_at"
  },
  {
    title: "需求方",
    dataIndex: "author",
    key: "author"
  },
  {
    title: "负责人",
    dataIndex: "principal",
    key: "principal"
  },
  {
    title: "任务数",
    dataIndex: "task_count",
    key: "task_count",
    scopedSlots: { customRender: "task_count" }
  },
  {
    title: "关联项目",
    dataIndex: "project",
    key: "project"
  }
];
const task_columns = [
  {
    title: "ID",
    dataIndex: "task_id"
  },
  {
    title: "关联需求",
    dataIndex: "requirement_name"
  },
  {
    title: "任务名称",
    dataIndex: "title"
  },
  {
    title: "工程师",
    dataIndex: "engineer_name"
  },
  {
    title: "对接人",
    dataIndex: "docking_name"
  },
  {
    title: "任务状态",
    dataIndex: "status",
    scopedSlots: { customRender: "status" },
    key: "status"
  },
  {
    title: "总耗时",
    dataIndex: "truly_time",
    scopedSlots: { customRender: "truly_time" }
  }
];
const task_columns1 = [
  {
    title: "ID",
    dataIndex: "task_id",
    scopedSlots: { customRender: "key" },
    key: "id",
    width: 55
    //   scopedSlots: { customRender: 'name' },
  },
  {
    title: "任务名称",
    dataIndex: "title",
    scopedSlots: { customRender: "haha" },
    key: "title"
  },
  {
    title: "工程师",
    dataIndex: "engineer",
    key: "engineer_id"
    // scopedSlots: { customRender: "files" },
  },
  {
    title: "开始时间",
    dataIndex: "started_at",
    key: "started_at"
    // ellipsis: true,
  },
  {
    title: "当前状态",
    dataIndex: "status",
    // scopedSlots: { customRender: "statu" },
    key: "status",
    align: "center"
  }
];
export default {
  name: "WorkPlace",
  components: { PageLayout },
  data() {
    return {
      task_data: [],
      task_columns,
      task_columns1,
      task_visible: false,
      requirement_columns,
      pagination: {},
      msg: "",
      animate: false,
      random: 0,
      project: [],
      projectNum: "",
      taskNum: "",
      produceNum: "",
      requirementNum: "",
      doingRequirement: [], //进行中的需求
      doingTask: [], //进行中的任务
      task_pagination: {
        size: "small",
        showSizeChanger: true,
        showQuickJumper: true,
        poposition: "bottom",
        pageSize: 5,
        current: 1,
        total: 0
      },
      loading: true,
      doingProject: [], //进行中的项目
      doingProduct: [], //进行中的产品
      loading: true,
      activities: [],
      current: 1,
      total: 100,
      userInfo: [],
      RequirementStatus: [
        {
          color: "#2591FF",
          text: "待审核"
        },
        {
          color: "#4E25FF",
          text: "排期中"
        },
        {
          color: "#FF6D25",
          text: "处理中"
        },
        {
          color: "yellowgreen",
          text: "待验收"
        }
      ]
    };
  },
  computed: {
    ...mapState("account", { currUser: "user" }),
    ...mapState("setting", ["lang", "avatarColor"])
  },
  activated() {
    this.random = Math.random();
  },
  created() {
    //获取cookie中的数据
    let userInfo = JSON.parse(window.localStorage.getItem("admin.user"));
    this.userInfo = userInfo;
    this.creaetTimeString();
    ongoing_projects().then((res) => {
      if (res.data.code === 20000) {
        // 取前六条
        this.project = res.data.data && res.data.data.splice(0, 6);
      }
    });
    // 项目总数
    projects().then((res) => {
      if (res.data.code === 20000) {
        // console.log(res.data);
        this.projectNum = res.data.data ? res.data.data : 0;
      }
    });
    // 需求数
    requirements().then((res) => {
      if (res.data.code === 20000) {
        // console.log(res.data);
        this.requirementNum = res.data.data;
      }
    });
    // 任务数
    tasks().then((res) => {
      if (res.data.code === 20000) {
        // console.log(res.data);
        this.taskNum = res.data.data ? res.data.data : 0;
      }
    });
    // 未完成数
    produces().then((res) => {
      if (res.data.code === 20000) {
        // console.log(res.data);
        this.produceNum = res.data.data ? res.data.data : 0;
      }
    });
    // 动态内容
    this.getLogs();
    //正在进行中的需求列表
    doing_requirements().then((res) => {
      if (res.data.code === 20000) {
        this.doingRequirement = res.data.data.data;
      }
    });
    // 正在进行中的任务列表
    const { pageSize, current } = this.pagination;
    this.loadTableData({ limit: pageSize, page: current });
  },
  methods: {
    hideModal(a) {
      this.task_visible = false;
      this.task_data = null;
    },
    task_infos(id) {
      this.getTasks(id);
      this.task_visible = true;

      //  console.log(id)
    },
    getTasks(id) {
      demand_task(id).then((res) => {
        if (res.data.code === 20000) {
          this.task_data = res.data.data;
          console.log(res.data);
          // this.$message.success(res.data.message);
        }
      });
    },
    handleTableChange(pagination, filters, sorter) {
      console.log(pagination);
      const pager = { ...this.pagination };
      pager.current = pagination.current;
      this.pagination = pager;
      this.fetch({
        results: pagination.pageSize,
        page: pagination.current,
        sortField: sorter.field,
        sortOrder: sorter.order,
        ...filters
      });
    },
    onChange(e) {
      const { current, pageSize } = e;
      this.loadTableData({ limit: pageSize, page: current });
    },
    // 请求table 的数据
    // obj 请求的字段
    loadTableData(obj) {
      this.loading = true;
      doing_task(obj).then((res) => {
        this.loading = false;
        if (res.data.code === 20000) {
            const { current_page, total, per_page } = res.data.data;
            Object.assign(this.task_pagination, {
              total: parseInt(total),
              current: parseInt(current_page),
              pageSize: parseInt(per_page)
            });
            this.doingTask = res.data.data.data;
        }
      });
    },
    fetch(params = {}) {
      console.log("params:", params);
      this.loading = true;
      reqwest({
        url: "https://randomuser.me/api",
        method: "get",
        data: {
          results: 10,
          ...params
        },
        type: "json"
      }).then((data) => {
        const pagination = { ...this.pagination };
        pagination.total = 200;
        this.loading = false;
        this.data = data.results;
        this.pagination = pagination;
      });
    },
    project_jump(peoject_id) {
      if (this.userInfo.permissions.projects_detail) {
        this.$router.push({
          path: "/project/detail",
          query: { random: this.random, id: peoject_id }
        });
      }
    },

    getLogs(data) {
      logs(data).then((res) => {
        this.loading = false;
        if (res.data.code === 20000) {
          this.activities = res.data.data.data.map((item) => {
            item.user_name = item.user_name ? item.user_name : "匿名用户";
            return item;
          });
          this.total = res.data.data.total;
          this.current = res.data.data.current_page;
        }
      });
    },
    paginationChange(page, pageSize) {
      this.loading = true;
      this.getLogs({ page });
    },
    // 时间段
    creaetTimeString() {
      let time = new Date().getHours();
      console.log(time, "time");
      if (time >= 6 && time < 12) {
        this.msg = "早上好";
      } else if (time >= 12 && time < 17) {
        this.msg = "下午好";
      } else if (time >= 17 && time < 19) {
        this.msg = "傍晚好";
      } else if (time >= 19 && time < 22) {
        this.msg = "晚上好";
      } else if (time >= 22) {
        this.msg = "深夜好";
      } else {
        this.msg = "凌晨好";
      }
    }
  },
  beforeDestroy() {
    // 清除定时器
    // clearInterval(this.setInterval);
    this.setInterval = null;
  }
};
</script>

<style lang="less">
@import "index";

</style>
